package org.istt.web;

import org.istt.domain.TimeHoliday;
import org.istt.service.TimeHolidayManager;

import com.opensymphony.xwork2.ActionContext;

/**
 * @author Huy
 *
 */
public class TimeHolidayAction extends BaseAction<TimeHolidayManager, TimeHoliday, Long> {
	private TimeHoliday timeHoliday;
	private Long id;
    
	/**
	 * 
	 */
	private static final long serialVersionUID = 9012754123343759656L;
	
	public void setId(Long id) {
		this.id = id;
	}
	@Override
	public Long getId() {
/*		Long id = NumberUtils.toLong(timeHoliday.getId());
		if (id == 0) return null;
		return id;*/
		return (timeHoliday==null? id : timeHoliday.getId());//id
	}


	@Override
	protected void setSaveMessage() {
        ActionContext.getContext().getSession().put("message", 
                getText("timeHoliday.saved"));
	}

	@Override
	protected void setDeleteMessage() {
        ActionContext.getContext().getSession().put("message", 
                getText("timeHoliday.deleted"));
	}


	@Override
	public String save() {
		if (log.isDebugEnabled()) {
            log.debug("entering 'save' method");
        }
        
        //entity = getEntity();
        ((TimeHolidayManager)mgr).save(timeHoliday);
        
        setSaveMessage();
                
        return SUCCESS;
	}

    
	public void setTimeHoliday(TimeHoliday timeHoliday) {
		this.timeHoliday = timeHoliday;
	}

	public TimeHoliday getTimeHoliday() {
		if (entity!= null && entity.getId() != null) {
			return entity;
		}		
		return timeHoliday;
	}
	
	public boolean isValid() {
		return mgr.isUnique(new String[]{"holidayName"}, new String[]{timeHoliday.getHolidayName()}, timeHoliday.getId());
	}

}
